package controllayer;

import java.util.ArrayList;

import dblayer.DBConnection;
import dblayer.DBReturn;
import dblayer.IFDBReturn;
import modellayer.Return;

public class CtrReturn {

	private IFDBReturn dbObj;
	private CtrPartSale partSale;
	
	public CtrReturn(){
		dbObj = new DBReturn();
		partSale = new CtrPartSale();
	}
	
	public ArrayList<Return> getAllReturns(){
		return dbObj.getAllReturns();
	}
	
	public Return searchByID(int id){
		return dbObj.searchByID(id);
	}
	
	public void createReturn(int part_sale, String itemName, String status, int amount){
		Return returnObj = new Return(partSale.searchByID(part_sale), itemName, status, amount);
		
		try{
			DBConnection.startTransaction();
			dbObj.insertReturn(returnObj);
			DBConnection.commitTransaction();
		}
		catch(Exception e){
			DBConnection.rollbackTransaction();
		}
	}
	
	public int updateReturn(int id, int part_sale, String itemName, String status, int amount){
		Return returnObj = new Return(id, partSale.searchByID(part_sale), itemName, status, amount);
		
		return dbObj.updateReturn(returnObj);
	}
	
	public int deleteReturn(int id){
		return dbObj.deleteReturn(id);
	}
	
}
